<%
Class Cemplate
	 Dim  LeftDelimiter,RightDelimiter
	 Dim KeyValues
	sub Class_Initialize()
		LeftDelimiter				=	"<{$"
		RightDelimiter				=	"}>"
		Set KeyValues=Server.CreateObject("Scripting.Dictionary")

	End Sub 
	Sub class_Terminate
		Set KeyValues = Nothing 
	End Sub 
	Sub Print()
		Dim mess,ki,keys
		keys=KeyValues.Keys
		for ki = 0 To KeyValues.Count -1
			mess = mess & keys(ki) & ":" & KeyValues.item( keys(ki) )  & "<br/>"
		Next 
		response.write(mess)
	End Sub 
	Sub Assign(keyStr,vaueStr)
		If(Len(keyStr)<1) Then Exit Sub 
		If(KeyValues.Exists(keyStr)=True) Then 
			KeyValues(keyStr) = vaueStr
		Else
			KeyValues.Add keyStr,vaueStr
		End If 
		
	End Sub 
	Function GetValue(keyStr)
		If(KeyValues.Exists(keyStr)) Then GetValue=KeyValues(keyStr)
	End Function 
	Sub AssignFile(keyStr,xmlFile,xslFile)
		If(Len(keyStr)<1) Then Exit Sub 
		Call Assign(keyStr,ReplaceTrimWord (InvokeXmlFileByXsl( Tpl.GetValue("BasePath") & xmlFile, Tpl.GetValue("BasePath") & xslFile)))
	End Sub 
	Sub AssignStr(keyStr,xmlStr,xslFile)
		If(Len(keyStr)<1) Then  Exit Sub 

		Call Assign(keyStr,ReplaceTrimWord(InvokeXmlStringByXsl(xmlStr, Tpl.GetValue("BasePath") & xslFile)))
	End Sub 
	 
	Function Fetch(fileStr)
		Dim kContent
		kContent= GetFileContext(Tpl.GetValue("BasePath") & fileStr)
		Fetch = ReplaceTrimWord(kContent)
	End Function 
	Private Function ReplaceTrimWord(kContent)
		Dim keys,ki
		keys=KeyValues.Keys
		for ki = 0 To KeyValues.Count -1
			kContent =Replace(kContent,LeftDelimiter & keys(ki) & RightDelimiter,KeyValues.item( keys(ki) ))
		Next 
		ReplaceTrimWord = kContent
	End Function 
	Function InvokeXmlFileByXsl(xmlFile,xslFile)
		'On Error Resume Next 
		Dim XMLDOM,o,outMe		 
		Set XMLDOM = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
		XMLDOM.async = true 
		XMLDOM.load( xmlFile )
		Set o=new Cls_Xml_Transform
		o.XSLTemplatefile= xslFile
		o.Input=XMLDOM
		o.Transform()
		outMe= o.Output()
		If Err Then
			outMe= (err.Description)
			err.Clear
		End if
		InvokeXmlFileByXsl=outMe
	End Function 
	Function InvokeXmlStringByXsl(xmlStr,xslFile)
		On Error Resume Next 
		Dim XMLDOM,o,outMe		 
		Set XMLDOM = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")'Microsoft.XMLDOM
		XMLDOM.async = false
		XMLDOM.loadXml( xmlStr )
		Set o=new Cls_Xml_Transform
		o.XSLTemplatefile= xslFile
		o.Input=XMLDOM
		o.Transform()
		outMe= o.Output()
		If Err Then
			outMe= (err.Description)
			err.Clear
		End if
		InvokeXmlStringByXsl=outMe
	End Function 
	Function GetFileContext(ByVal filename)
		Dim objStream,fget
		On Error Resume Next
		Set objStream = Server.CreateObject("ADODB.Stream")
		With objStream
			.Type = 2
			.Mode = 3
			.Open
			.LoadFromFile filename
			If Err.Number<>0 Then
				GetFileContext =  filename & " 不存在"
				Err.Clear
				Exit Function 
			End If
			.Charset = Response.Charset 
			.Position = 2
			GetFileContext = .ReadText
			.Close
		End With
		Set objStream = Nothing
	End Function
End Class 
Class Cls_Xml_Transform
    Private lInput,XSLTemplate
    Private p_Output
    Public Property Get Output()
        Output = p_Output
    End Property
    Private Property Let Output(ByVal strInfo)
        p_Output = strInfo
    End Property

    Public Property Let Input(ByVal vNewValue)
        If IsObject(vNewValue) Then Set lInput=vNewValue
    End Property

    Public Property Let XSLTemplatefile(ByVal vNewValue)
        Dim StyleSheet
        Dim vNewValue_

        vNewValue_ = vNewValue

        If Not InStr(vNewValue,":\") > 0 Then
            vNewValue  = Server.MapPath(vNewValue)
        End If

        Set XSLTemplate=Server.CreateObject("Msxml2.XSLTemplate")
        Set StyleSheet=Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
        StyleSheet.load vNewValue
        XSLTemplate.StyleSheet=StyleSheet
    End Property

    Public Sub Transform()
        Dim proc
        Set proc = XSLTemplate.createProcessor()
        proc.input=linput
        proc.transform()
        Output=proc.output
        Set proc=Nothing
    End Sub

End Class
%>